package com.yykj.hospital.server.controller;

import com.yykj.common.enums.HospitalOnlineTypeEnum;
import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.DepartmentListDTO;
import com.yykj.hospital.client.dto.HospitalDTO;
import com.yykj.hospital.client.dto.HospitalDepartmentDTO;
import com.yykj.hospital.client.dto.HospitalOfficerDTO;
import com.yykj.hospital.server.dto.DoctorHomeOnlineDTO;
import com.yykj.hospital.server.dto.HospitalNavigatorTitleListDTO;
import com.yykj.hospital.server.enums.HospitalNoticeTypeEnum;
import com.yykj.hospital.server.form.*;
import com.yykj.hospital.server.form.train.FormTrainSearchForm;
import com.yykj.hospital.server.model.entity.*;
import com.yykj.hospital.server.model.entity.form.template.FormTrain;
import com.yykj.hospital.server.model.entity.qrcode.DoctorQrcode;
import com.yykj.hospital.server.service.*;
import com.yykj.hospital.server.service.from.template.FormTrainService;
import com.yykj.hospital.server.service.qrcode.QrcodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/hospital/patient/client")
@Api(tags = {"患者端 APP 首页需要的接口--不需要token的"})
@SuppressWarnings("unchecked")
public class PatientClientHomeController {

    @GetMapping("/hot/department/list")
    @ApiOperation("热门科室--科室列表")
    public ResultVO<List<HospitalDepartmentDTO>> listHotDepartment(@RequestParam(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(departmentService.listHotDepartment(hospitalId));
    }

    @GetMapping("/search/department")
    @ApiOperation("搜索 -- 医院科室列表")
    public ResultVO<List<DepartmentListDTO>> getHospitalDepartment(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                                   @RequestParam(name = "name", required = false) String name
    ) {

        HospitalDepartmentSearchFrom hospitalDepartmentSearchFrom = HospitalDepartmentSearchFrom.builder()
                .hospitalId(hospitalId)
                .name(name)
                .build();
        return ResultVO.success(departmentService.getHospitalDepartment(hospitalDepartmentSearchFrom));
    }

    @GetMapping("/search/expert/doctor")
    @ApiOperation("首页 -- 推荐专家")
    public ResultVO<List<DoctorHomeOnlineDTO>> listHomeExpertDoctor(@RequestParam("hospitalId") Integer hospitalId) {
        return ResultVO.success(doctorService.listHomeExpertDoctor(hospitalId));
    }

    @GetMapping("/banner/list/{hospitalId}")
    @ApiOperation("首页 -- banner")
    public ResultVO<List<HospitalBanner>> listHospitalBanner(@PathVariable("hospitalId") Integer hospitalId) {
        return ResultVO.success(hospitalService.listBanner(hospitalId));
    }

    @GetMapping("/search/doctor")
    @ApiOperation("搜索医生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId", value = "医院ID", required = true, type = "Integer"),
            @ApiImplicitParam(name = "depId", value = "科室ID", required = false, type = "Integer"),
            @ApiImplicitParam(name = "type", value = "问诊方式", required = false, type = "HospitalOnlineTypeEnum"),
            @ApiImplicitParam(name = "doctorName", value = "医生名称", required = false, type = "String"),
            @ApiImplicitParam(name = "officer", value = "职称", required = false, type = "String"),
            @ApiImplicitParam(name = "label", value = "医生标签/热门疾病", required = false, type = "String"),
            @ApiImplicitParam(name = "sortPraise", value = "好评率排序,0正序，1倒序", required = false, type = "Integer"),
            @ApiImplicitParam(name = "sortTreatmentCnt", value = "接诊量排序，0正序，1倒序", required = false, type = "Integer"),

    })
    public ResultVO<List<DoctorHomeOnlineDTO>> listHomeDoctor(@RequestParam("hospitalId") Integer hospitalId,
                                                              @RequestParam(value = "depId", required = false) Integer depId,
                                                              @RequestParam(value = "type", required = false) HospitalOnlineTypeEnum type,
                                                              @RequestParam(value = "doctorName", required = false) String doctorName,
                                                              @RequestParam(value = "officer", required = false) String officer,
                                                              @RequestParam(value = "label", required = false) String label,
                                                              @RequestParam(value = "sortPraise", required = false) Integer sortPraise,
                                                              @RequestParam(value = "sortTreatmentCnt", required = false) Integer sortTreatmentCnt
    ) {

        HomeSearchDoctorForm form = HomeSearchDoctorForm.builder()
                .hospitalId(hospitalId)
                .depId(depId)
                .type(type)
                .doctorName(doctorName)
                .officer(officer)
                .label(label)
                .sortPraise(sortPraise)
                .sortTreatmentCnt(sortTreatmentCnt)
                .build();

        return ResultVO.success(doctorService.listHomeDoctor(form));
    }

    @GetMapping("/doctor/info/{doctorId}")
    @ApiOperation("在线问诊--单个医生详情")
    public ResultVO<DoctorHomeOnlineDTO> viewHomeDoctor(@PathVariable("doctorId") String doctorId) {
        return ResultVO.success(doctorService.viewHomeDoctor(doctorId));
    }


    @ApiOperation("医院 -- 医院信息")
    @GetMapping("/hospital/info/{hospitalId}")
    public ResultVO<HospitalDTO> hospitalInfo(@PathVariable Integer hospitalId) {
        return ResultVO.success(hospitalService.getHospitalInfo(hospitalId));
    }

    @ApiOperation("医院 -- 就医指南")
    @GetMapping("/hospital/guide")
    public ResultVO<HospitalGuide> listHospitalGuide(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                     @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        HospitalGuideListForm form = HospitalGuideListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .status(true)
                .build();

        return ResultVO.success(guideService.listHospitalGuide(form));
    }

    @ApiOperation("医院 -- 医院交通")
    @GetMapping("/hospital/traffic")
    public ResultVO<HospitalTraffic> listHospitalTraffic(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                         @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        HospitalTrafficListForm form = HospitalTrafficListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .status(true)
                .build();

        return ResultVO.success(trafficService.listHospitalTraffic(form));
    }

    @ApiOperation("医院 -- 医院公告")
    @GetMapping("/hospital/notice")
    public ResultVO<HospitalNotice> listHospitalNotice(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                       @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        HospitalNoticeListForm form = HospitalNoticeListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .type(HospitalNoticeTypeEnum.patient)
                .pageSize(pageSize)
                .status(true)
                .build();

        return ResultVO.success(noticeService.listHospitalNotice(form));
    }

    @ApiOperation("医院 -- 医院导行--搜索标题")
    @GetMapping("/hospital/navigator/title/{hospitalId}")
    public ResultVO<List<HospitalNavigatorTitleListDTO>> listNavigatorTitle(@PathVariable(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(navigatorService.listNavigatorTitle(hospitalId));
    }

    @ApiOperation("医院 -- 医院导行 -- 内容")
    @GetMapping("/hospital/navigator/info/{id}")
    public ResultVO<HospitalNavigator> listHospitalNavigator(@PathVariable(name = "id") Integer id) {
        return ResultVO.success(navigatorService.navigatorInfo(id));
    }


    @GetMapping("/info/{id}")
    @ApiOperation("科室信息")
    public ResultVO<HospitalDepartmentDTO> info(@PathVariable(name = "id") Integer id) {
        return ResultVO.success(departmentService.getDepartment(id));
    }


    @GetMapping("/officer/list")
    @ApiOperation("职称--列表")
    public ResultVO<HospitalOfficerDTO> listHospitalDepartment(@RequestParam(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(hospitalService.listHospitalOfficer(hospitalId));
    }

    @ApiOperation("标签 -- 列表")
    @GetMapping("/label/list")
    public ResultVO<PageData<HospitalLabel>> listHospitalLabel(@RequestParam Integer hospitalId) {
        return ResultVO.success(hospitalLabelService.listAllHospitalLabel(hospitalId));
    }


    @ApiOperation("直通车 -- 列表")
    @GetMapping("/form/train/list")
    public ResultVO<PageData<FormTrain>> listFormTrain(FormTrainSearchForm searchForm) {
        return ResultVO.success(formTrainService.listFormTrain(searchForm));
    }

    @ApiOperation("患者端二维码 -- 参数信息")
    @GetMapping("/qrcode/info/{qrId}")
    public ResultVO<DoctorQrcode> getDoctorQrcodeParam(@PathVariable Integer qrId) {
        DoctorQrcode qrcode = qrcodeService.getDoctorQrcodeParam(qrId);
        return ResultVO.success(qrcode);
    }

    private QrcodeService qrcodeService;

    private FormTrainService formTrainService;

    private DepartmentService departmentService;

    private HospitalDoctorService doctorService;

    private HospitalService hospitalService;

    private HospitalGuideService guideService;

    private HospitalTrafficService trafficService;

    private HospitalNavigatorService navigatorService;

    private HospitalNoticeService noticeService;

    private HospitalLabelService hospitalLabelService;


    @Autowired
    public void setDepartmentService(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @Autowired
    public void setDoctorService(HospitalDoctorService doctorService) {
        this.doctorService = doctorService;
    }

    @Autowired
    public void setHospitalService(HospitalService hospitalService) {
        this.hospitalService = hospitalService;
    }

    @Autowired
    public void setGuideService(HospitalGuideService guideService) {
        this.guideService = guideService;
    }

    @Autowired
    public void setTrafficService(HospitalTrafficService trafficService) {
        this.trafficService = trafficService;
    }

    @Autowired
    public void setNavigatorService(HospitalNavigatorService navigatorService) {
        this.navigatorService = navigatorService;
    }

    @Autowired
    public void setNoticeService(HospitalNoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @Autowired
    public void setHospitalLabelService(HospitalLabelService hospitalLabelService) {
        this.hospitalLabelService = hospitalLabelService;
    }

    @Autowired
    public void setFormTrainService(FormTrainService formTrainService) {
        this.formTrainService = formTrainService;
    }

    @Autowired
    public void setQrcodeService(QrcodeService qrcodeService) {
        this.qrcodeService = qrcodeService;
    }
}
